﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using OgilvyOne.Model;
using OgilvyOne.BLL;

public partial class admin_manager_role_add : AdminBasePage
{
    string addrolename;
    string addremark;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.PopedomValidate(Layerid, ADD);
            header.Text = new ColumnBll().LayeridSysColumnNaiv(Layerid);
        }
        if (IsPostBack)
        {
            addrolename = rolename.Value;
            addremark = re.Value;
        }
       
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            RoleModel model = new RoleModel();
            model.Addtime = DateTime.Now;
            model.Remark = addremark;
            model.Rolename = addrolename;
            if (addrolename == null || addrolename.Trim().ToString() == "")
            {
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('角色名称不能为空！');", true);
                return;
            }       
            if (addremark == null || addremark.Trim().ToString() == "")
            {
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('备注不能为空！');", true);
                return;
            }
              
            RoleBll bll = new RoleBll();
            if (!bll.Exists(addrolename,0))
            {
                bool add = bll.Add(model);
                if (add)
                {
                    Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('添加成功！');window.location=\"role_list.aspx?layerid="+Layerid+"\"", true);
                }
                else
                {
                    Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('添加失败！');window.location=\"role_list.aspx?layerid=" + Layerid + "\"", true);
                }
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('角色名已存在！请重新输入！');", true);
            }
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('" + ex.ToString() + "');window.location=\"role_list.aspx?layerid=" + Layerid + "\"", true);
        }
    }
}


